import axios from 'axios';
import config from './config';
import CryptoJS from 'crypto-js';

const PASSWORD_SECRET = 'password_secret_456';

const apiClient = axios.create({
  baseURL: config.API_BASE_URL,
  headers: { 'Content-Type': 'application/json' }
});



// 📁 src/api/signin.js

// 用户签到
export const userSignin = async (userId) => {
    try {
      const token = localStorage.getItem('token');
      if (!token) return { success: false, message: '请先登录' };
  
      const response = await apiClient.post('/signin', { user_id: userId }, {
        headers: { Authorization: `Bearer ${token}` }
      });
  
      return { success: true, message: response.data.message };
    } catch (error) {
      return {
        success: false,
        message: error.response?.data?.message || '签到失败'
      };
    }
  };
  
  // 获取签到记录
  export const getSigninRecords = async (userId) => {
    try {
      const token = localStorage.getItem('token');
      if (!token) return { success: false, message: '请先登录' };
  
      const response = await apiClient.get(`/signin-records/${userId}`, {
        headers: { Authorization: `Bearer ${token}` }
      });
  
      return { success: true, records: response.data.records };
    } catch (error) {
      return {
        success: false,
        message: error.response?.data?.message || '获取签到记录失败'
      };
    }
  };
  